﻿<!DOCTYPE HTML>
<html lang="zh-cn">
<head>
	<meta charset="utf-8">
	<meta http-equiv="X-UA-Compatible" content="IE=edge">
	<meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
	<title></title>

	<link href="../plugins/bootstrap-3.3.0/css/bootstrap.min.css" rel="stylesheet"/>
	<link href="../plugins/material-design-iconic-font-2.2.0/css/material-design-iconic-font.min.css" rel="stylesheet"/>
	<link href="../plugins/bootstrap-table-1.11.0/bootstrap-table.min.css" rel="stylesheet"/>
	<link href="../plugins/waves-0.7.5/waves.min.css" rel="stylesheet"/>
	<link href="../plugins/jquery-confirm/jquery-confirm.min.css" rel="stylesheet"/>
	<link href="../plugins/select2/css/select2.min.css" rel="stylesheet"/>

	<link href="../css/common.css" rel="stylesheet"/>
</head>
<body>
<div id="main">
	<table id="table"></table>
</div>
<script src="../plugins/jquery.1.12.4.min.js"></script>
<script src="../plugins/bootstrap-3.3.0/js/bootstrap.min.js"></script>
<script src="../plugins/bootstrap-table-1.11.0/bootstrap-table.min.js"></script>
<script src="../plugins/bootstrap-table-1.11.0/locale/bootstrap-table-zh-CN.min.js"></script>
<script src="../plugins/waves-0.7.5/waves.min.js"></script>
<script src="../plugins/jquery-confirm/jquery-confirm.min.js"></script>
<script src="../plugins/select2/js/select2.min.js"></script>
<script src="../js/bootstrap-table-super-search.js"></script>
<script src="../js/common.js"></script>
<script>
var $table = $('#table');
$(function() {
	$(document).on('focus', 'input[type="text"]', function() {
		$(this).parent().find('label').addClass('active');
	}).on('blur', 'input[type="text"]', function() {
		if ($(this).val() == '') {
			$(this).parent().find('label').removeClass('active');
		}
	});
	$table.bootstrapTable({
		url: '/admin/get/user',
		method:'get',
		height: getHeight(),
		striped: true,
		search: false,
		searchOnEnterKey: false,
		superSearch:false,
        superSearchAlign:'right',
		showColumns: false,
		minimumCountColumns: 2,
		clickToSelect: true,
		detailFormatter: 'detailFormatter',
		pagination: true,
        paginationLoop: false,
		classes: 'table table-hover table-no-bordered',
		sidePagination: 'server',
		smartDisplay: true,
		idField: 'id',
        uniqueId:'id',
		escape: true,
        showRefresh:true,
        showToggle:true,
		toolbar: '#toolbar',
		columns: [
			{field: 'state', checkbox: true},
			{field: 'id', title: '编号', align: 'center'},
			{field: 'username', title: '账号', align: 'center'},
			{field: 'password', title: '密码', align: 'center'},
            {field: 'coin', title: '积分', align: 'center'},
			{field: 'action', title: '操作', align: 'center', formatter: 'actionFormatter', events: 'actionEvents', clickToSelect: false}
		],
	}).on('all.bs.table', function (e, name, args) {
		$('[data-toggle="tooltip"]').tooltip();
		$('[data-toggle="popover"]').popover();  
	});
});
function actionFormatter(value, row, index) {
    return [
        '<a class="remove ml10" href="javascript:void(0)" data-toggle="tooltip" title="删除用户"><i class="glyphicon glyphicon-remove"></i></a>'
    ].join('');
}

window.actionEvents = {
    'click .remove': function (e, value, row, index) {
        var userRows = $table.bootstrapTable('getSelections');
        if(JSON.stringify(userRows).indexOf(row.id)!=-1){
            $.ajax({
                url: '/admin/delete/user',
                type: 'POST',
                data: {id:row.id,},
                success: function(json){
                    if(json.status){
                        $.alert({
                            content:'删除错误！',
                            title:false,
                            closeIcon:false
                        });
                    }else{
                        $table.bootstrapTable('removeByUniqueId',row.id);
                        $.alert({
                            content:'删除成功！',
                            title:false,
                            closeIcon:false
                        });
                    }
                },
                error: function(error){
                    console.log(error);
                }
            });
		}else{
            $.alert({content:'请先选择你要删除的用户！', title:false, closeIcon:false});
		}
    }
};

function detailFormatter(index, row) {
	var html = [];
	$.each(row, function (key, value) {
		html.push('<p><b>' + key + ':</b> ' + value + '</p>');
	});
	return html.join('');
}
</script>
</body>
</html>